import jsonp from 'jsonp';
import validateToken from './validate-token'


export default function appJsonp(options = {}) {
    let url = '//u.jss.com.cn/u/v1/auth/check_login'
    
    if (options.data) {
        const obj = options.data
        const arr = []
        for (let key in obj) {
            arr.push(`${key}=${obj[key]}`)
        }
        url += '?' + arr.join('&')
    }

    jsonp(url, {
        param: "callback",
        name: "user_lbn_jsonpResponse"
    }, (err, res) => {
        if (!err && res && res.data && res.data.token) {
            validateToken(res.data.token)
        }else{
            console.log(err, res)
        }
    })
}

